package vue;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.GroupLayout;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;

import controleur.CExit;
import controleur.CNewLevel;

import memory.Memory;

@SuppressWarnings("serial")
public class VEndBar extends JPanel {
	
	protected JButton replay, next;
	
	public VEndBar(VRootWindow rw, int h, int l, int th) {
		setPreferredSize(new Dimension(1024, 100));
		setBackground(Memory.BG_COLOR);
		
		replay = new JButton("Recommencer");
		try {
			ImageIcon replayIcon = new ImageIcon(ImageIO.read(getClass().getResourceAsStream("replay.png")));
			replay.setIcon(replayIcon);
		} catch (IOException e) {}

		next = new JButton("Niveau suivant");
		try {
			ImageIcon nextIcon = new ImageIcon(ImageIO.read(getClass().getResourceAsStream("next.png")));
			next.setIcon(nextIcon);
		} catch (IOException e) {}
		
		if(h==2 && l==2) {
			replay.addActionListener(new CNewLevel(null, rw, 1, th));
			next.addActionListener(new CNewLevel(null, rw, 2, th));
		}
		else if(h==2 && l==3) {
			replay.addActionListener(new CNewLevel(null, rw, 2, th));
			next.addActionListener(new CNewLevel(null, rw, 3, th));
		}
		else if(h==2 && l==4) {
			replay.addActionListener(new CNewLevel(null, rw, 3, th));
			next.addActionListener(new CNewLevel(null, rw, 4, th));
		}
		else if(h==3 && l==4) {
			replay.addActionListener(new CNewLevel(null, rw, 4, th));
			next.setText("Retour au menu");
			next.addMouseListener(new CExit(rw));
		}
		JPanel content = new JPanel();
		 content.setLayout(new BorderLayout());
		 content.add(replay, BorderLayout.WEST);
		 content.add(next, BorderLayout.EAST);
		 content.setBackground(Memory.BG_COLOR);
		 
		 GroupLayout layout = new GroupLayout(this);
		 setLayout(layout);
		 layout.setAutoCreateContainerGaps(true);
		 layout.setHorizontalGroup(
				 layout.createSequentialGroup().addComponent(content));
		 layout.setVerticalGroup(
				 layout.createParallelGroup().addComponent(content));
	}

	protected JButton getReplay()
	{
		return replay;
	}

	protected JButton getNext()
	{
		return next;
	}

}
